<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>发货</title>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/table.css">
    <link rel="stylesheet" href="${ctx}/css/ui/circle/add_cmember.css">
    <%@include file="../include/commonFile.jsp" %>
    <style type="text/css">
        body {
            min-width: auto !important;
            background-color: white !important;
        }

        .info-container {
            padding-top: 10px;
            margin: 0px auto;
            width: 90%;
        }

        .info-container div {
            line-height: 30px !important;
        }

        .info-container .member-logo {
            margin-bottom: 0;
            position: relative;
        }

        html {
            overflow: initial !important;
        }

        .layui-form-select dl {
            max-height: 148px !important;
        }
    </style>
</head>
<body>
<div class="layui-form info-container">
    <form class="layui-form" id="infoForm" method="post">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label" style="width: 70px;padding-left: 0px;">快递公司</label>
                <div class="layui-input-inline">
                    <select name="courierCode" lay-search>
                        <option value="">请选择</option>
                        <c:forEach var="express" items="${couriers}">
                            <option value="${express.code}" ${parcelOut.courierCode == express.code ? 'selected' : ''}>${express.name}</option>
                        </c:forEach>
                    </select>
                    <input type="hidden" name="courierName"/>
                    <input type="hidden" name="goodsTargetIds" value="${targetId}"/>
                    <input type="hidden" name="targetId" value="${targetId}"/>
                    <input type="hidden" name="logisticsId" value="${parcelOut.logisticsId}"/>
                    <input type="hidden" name="type" value="2">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label" style="width: 70px;padding-left: 0px;">快递单号</label>
                <div class="layui-input-inline">
                    <input class="layui-input" name="courierNumber" lay-verify="required" autocomplete="off"
                           value="${parcelOut.courierNumber}"/>
                </div>
            </div>
        </div>
    </form>
</div>
<!--底部-->
<%@include file="../include/incScript.jsp" %>
<script type="text/javascript">
    var form = null;
    $(function () {
        layui.use(['form'], function () {
            form = layui.form;
            form.render('select');
        });
    })

    function doSubmit() {
        var code = $("[name=courierCode]").find("option:selected").val();
        if (code == "") {
            util.layerMsgError("请先选择快递公司")
            return false;
        }
        var courierName = $("[name=courierCode]").find(":selected").text();
        $("[name=courierName]").val(courierName);

        var courierNum = $("[name=courierNumber]").val();
        if (courierNum == "") {
            util.layerMsgError("请输入快递单号")
            return false;
        }

        var url = '${ctx}/logistics/logistics/doShipment.do';
        if (util.isValid('${parcelOut.logisticsId}')) {
            url = '${ctx}/logistics/logistics/updateGiftShipment.do';
        }
        $.ajax({
            type: 'POST',
            async: false, // 使用同步的方法
            data: $("#infoForm").serializeArray(),
            dataType: 'json',
            success: function (res) {
                if (res.success) {
                    util.layerMsgSuccess("发货成功")
                } else {
                    util.layerMsgError("发货失败")
                }
            },
            url: url
        });
        return true;
    }
</script>
</body>
</html>